package com.xm.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wxm.servlet.BaseServlet;
import com.xm.dao.ComdeDaoImp;
import com.xm.entity.Banners;
import com.xm.entity.Comdetail;
import com.xm.uti.Result;


/**
 * 处理公司表的后台请求
 */
@WebServlet("/admin/ComdeServletAdmin")
public class ComdeServletAdmin extends BaseServlet {

	ComdeDaoImp comDao = new ComdeDaoImp();

  /**
   * 查列表
   * 
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
	
  public void getComdeList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    // 调用dao层的方法，获取所有员工
     Comdetail comd=comDao.getCom();
     
    // 调用结果工具类，将数据返回
    String res = Result.toClient(0, "公司列表", comd);
    
    PrintWriter out = resp.getWriter(); // 获取输出对象
    out.print(res); // 输出数据
    out.flush(); // 刷新
    out.close(); // 关闭

  }
  
  /**
   * 修改公司内容
   * 
   * @param req
   * @param resp
   * @throws ServletException
   * @throws IOException
   */

  public void updateComde(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    // 1.接收客户端传来的参数
    String id = req.getParameter("id");
    String comname = req.getParameter("comname");
    String detail = req.getParameter("detail");
    String zhaoshang = req.getParameter("zhaoShang");
    String tel = req.getParameter("tel");
    String address = req.getParameter("address");
    String email = req.getParameter("email");
    String culture = req.getParameter("culture");
    String jianjie = req.getParameter("jianjie");
    String x = req.getParameter("x");
    String y = req.getParameter("y");
    System.out.println("接收的参数是" + id + comname + detail + zhaoshang + tel + address + email + culture + jianjie + x + y);
    int id2 = 0;
    if (id != null && !id.equals("")) {
      id2 = Integer.valueOf(id);
    }
    // 2.调用dao层的添加方法    
    Comdetail comdetail = new Comdetail (id2, comname , detail , zhaoshang , tel , address , email , culture , jianjie, Double.valueOf(x),Double.valueOf(y));
    boolean res = comDao.updateCom(comdetail);
    // 3.判断结果，实现跳转
    if (res == true) {// 修改成功
      resp.sendRedirect("ComdeServletAdmin?method=getComdeList");
    } else {// 修改失败
      req.setAttribute("res", "修改失败");
      req.getRequestDispatcher("companyList.jsp").forward(req, resp);
    }
    PrintWriter out = resp.getWriter(); // 获取输出对象
    out.flush(); // 刷新
    out.close(); // 关闭

  }

}